package com;

import com.pojo.Employee;
import com.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

public class EmployeeTest {
    @Test
    public void findEmployeeTest(){
        SqlSession session = MyBatisUtils.getSession();
        Employee employee =  session.
                selectOne("com.mapper.EmployeeMapper.selectByPrimaryKey",(long)1);
        System.out.println(employee);
        session.commit();
        session.close();
    }
    @Test
    public void addEmployeeTest(){
        SqlSession session = MyBatisUtils.getSession();
        Employee employee = new Employee();
        employee.setName("王八");
        employee.setAge(18);
        employee.setPosition("员工");
        int rows = session.insert("com.mapper.EmployeeMapper.insert",employee);
        System.out.println(rows);
        session.commit();
        session.close();
    }
    @Test
    public void updateEmployeeTest(){
        SqlSession session = MyBatisUtils.getSession();
        Employee employee = new Employee();
        employee.setId(7);
        employee.setName("周琪");
        employee.setAge(20);
        employee.setPosition("员工");
        int rows= session.delete("com.mapper.EmployeeMapper.deleteByPrimaryKey",5L);
        System.out.println(rows);
        session.commit();
        session.close();
    }
}